package com.lanou.horo.zhuizhui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.zhuizhui.entity.SelectedAlbumItem;
import com.lanou.horo.zhuizhui.utility.imageLoader.AsyncImageLoader;
import com.lanou.horo.zhuizhui.R;
import com.lanou.horo.zhuizhui.utility.imageLoader.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/27.
 */
public class SelectedAlbumAdapter extends
        RecyclerView.Adapter<SelectedAlbumAdapter.SelectedAlbumViewHolder> {
    private List<SelectedAlbumItem.ContentListsEntity> listsEntities;
    private ImageLoader imageLoader;
    private Context context;

    public SelectedAlbumAdapter(Context context) {
        this.context = context;
        imageLoader = VolleySingleton.getInstance().getImageLoader();
    }

    public void addConList(List<SelectedAlbumItem.ContentListsEntity> datas) {
        listsEntities = datas;
        notifyDataSetChanged();
    }

    @Override
    public SelectedAlbumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.activity_album_selected_item, null);
        return new SelectedAlbumViewHolder(view);
    }

    @Override
    public void onBindViewHolder(SelectedAlbumViewHolder holder, int position) {
        if (listsEntities != null && listsEntities.size() > 0) {
            SelectedAlbumItem.ContentListsEntity listsEntity = listsEntities.get(position);
            holder.titleTv.setText(listsEntity.getTitle());
            holder.comicCountTv.setText("共" + listsEntity.getComic_count() + "本");
            holder.nameTv.setText("来自" + listsEntity.getUser_info().getName());
            if (listsEntity.getBest() == 1) {
                holder.imageViewBest.setImageResource(R.mipmap.best);
            }
            String urlf = listsEntity.getCovers().get(0);
            holder.imageViewf.setImageUrl(urlf, imageLoader);
            String urls = listsEntity.getCovers().get(1);
            holder.imageViews.setImageUrl(urls, imageLoader);
            String urlt = listsEntity.getCovers().get(2);
            holder.imageViewt.setImageUrl(urlt, imageLoader);
            String urlo = listsEntity.getCovers().get(3);
            holder.imageViewo.setImageUrl(urlo, imageLoader);
        }

    }

    @Override
    public int getItemCount() {
        return listsEntities != null && listsEntities.size() > 0 ? listsEntities.size() : 0;
    }

    public class SelectedAlbumViewHolder extends RecyclerView.ViewHolder {
        private TextView titleTv, comicCountTv, nameTv;
        private NetworkImageView imageViewf, imageViews, imageViewt, imageViewo, imageViewBest;

        public SelectedAlbumViewHolder(View itemView) {
            super(itemView);
            titleTv = (TextView) itemView.findViewById(R.id.titleTv);
            comicCountTv = (TextView) itemView.findViewById(R.id.comicCountTv);
            nameTv = (TextView) itemView.findViewById(R.id.nameTv);
            imageViewBest = (NetworkImageView) itemView.findViewById(R.id.imageViewBest);
            imageViewf = (NetworkImageView) itemView.findViewById(R.id.imageViewf);
            imageViews = (NetworkImageView) itemView.findViewById(R.id.imageViews);
            imageViewt = (NetworkImageView) itemView.findViewById(R.id.imageViewt);
            imageViewo = (NetworkImageView) itemView.findViewById(R.id.imageViewo);
        }
    }
}
